﻿using Fuyao.Win.UI.Common;
using Fuyao.Win.UI.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Fuyao.Win.UI.Reportes
{
    public partial class frmReportes : Form
    {
        public frmReportes()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.ControlBox = false;
            this.WindowState = FormWindowState.Maximized;
            this.BringToFront();
        }

        private void btnImprimirDatos_Click(object sender, EventArgs e)
        {
            if (rbtnReportePagadosPendientes.Checked)
            {
                int EstadoVenta = 0;

                if (rbtnPagado.Checked)
                {
                    EstadoVenta = 2;
                }
                else if (rbtnPendiente.Checked)
                {
                    EstadoVenta = 1;
                }

                rptVentasPagadasPendientes rpt = new rptVentasPagadasPendientes();
                DataTable dt =
                    (DataTable)(new Fuyao.Win.UI.Reportes.dsReportesTableAdapters.VentasPagadasPendientesTableAdapter().VentasPagadasPendientes(EstadoVenta,0));
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                rpt.SetDataSource(ds);
                crvGeneralViewer.ReportSource = rpt;
            }
            else if (rbtnReporteVentaPorModelo.Checked)
            {
                string categoriaAuto = this.cboCategoriaProducto.SelectedValue.ToString();

                if (cboCategoriaProducto.SelectedIndex == 0)
                    categoriaAuto = string.Empty;

                rptVentasVentasCategoriaAuto rpt = new rptVentasVentasCategoriaAuto();
                DataTable dt =
                    (DataTable)(new Fuyao.Win.UI.Reportes.dsReportesTableAdapters.VentasPorCategoriaAutoTableAdapter().GetData(categoriaAuto,0));
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                rpt.SetDataSource(ds);
                crvGeneralViewer.ReportSource = rpt;
            }
            else if (rbtnReporteVentasChequeEfectivo.Checked)
            {
                int formaPago = Convert.ToInt32(cboTipodePago.SelectedValue);

                rptVentasFormaPago rpt = new rptVentasFormaPago();
                DataTable dt =
                    (DataTable)(new Fuyao.Win.UI.Reportes.dsReportesTableAdapters.VentasPagadasPendientesTableAdapter().VentasPagadasPendientes(0, formaPago));
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                rpt.SetDataSource(ds);
                crvGeneralViewer.ReportSource = rpt;
            }
            else if (rbtnReporteVentasPorDia.Checked)
            {
                rptVentasPorDia rpt = new rptVentasPorDia();
                DataTable dt =
                    (DataTable)(new Fuyao.Win.UI.Reportes.dsReportesTableAdapters.VentasPorCliente_Vendedor_Dia_ProductoTableAdapter().VentasPorCliente_Fecha_Vendedor_Cliente_Producto(dtpFechaVentaInicial.Value, dtpFechaVentaFinal.Value));
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                rpt.SetDataSource(ds);
                rpt.SetParameterValue("FechaInicial", dtpFechaVentaInicial.Value.ToShortDateString());
                rpt.SetParameterValue("FechaFinal", dtpFechaVentaFinal.Value.ToShortDateString());

                crvGeneralViewer.ReportSource = rpt;
            }
            else if (rbtnVentaPorGuiaInterna.Checked)
            {
                rptVentasPorGuiaInterna rpt = new rptVentasPorGuiaInterna();
                DataTable dt =
                    (DataTable)(new Fuyao.Win.UI.Reportes.dsReportesTableAdapters.VentasPorCategoriaAutoTableAdapter().GetData(string.Empty, Convert.ToInt32(Utilitarios.IsNumericWithReturnValue(txtGuiaInterna.Text))));
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                rpt.SetDataSource(ds);
                crvGeneralViewer.ReportSource = rpt;
            }
        }

        private void frmReportes_Load(object sender, EventArgs e)
        {
            Utilitarios.cargarCategoriaProducto(this.cboCategoriaProducto);
            Utilitarios.cargarCboEstadosParametrosTable(this.cboTipodePago, Constantes.PARAMETRO_FormaPago);
        }
    }
}
